﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using MLM.AdminCP.Class;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using MLM.Data;
using System.Data;
using MLM.Base;

namespace MLM.AdminCP.Pages
{
    public partial class SettingUser : BasePage
    {
        static GridEditableItem item;
        static String a;
        static int count = 0;
        long userid2;
        static String country;
        protected override void OnInit(EventArgs e)
        {
            Permission.CheckIsAdmin();
            base.OnInit(e);
        }
        protected void OnItemDataBoundHandler(object sender, GridItemEventArgs e)
        {

        //    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        //    {
        //        item = e.Item as GridEditFormItem;
        //        RadComboBox cbbCategory = item.FindControl("RadCountryID") as RadComboBox;
        //        country = "1";

        //        if (cbbCategory.SelectedValue != "")
        //        {
        //            country = cbbCategory.SelectedValue;
        //        }
        //        //cbbCategory.DataBind();
        //        RadTextBox tbUserid = item.FindControl("RadTextBox7") as RadTextBox;
                
        //        if (tbUserid.Text != "")
        //        {
        //            String userid = tbUserid.Text;
        //            userid2 = Convert.ToInt64(userid);
        //        }
        //        else {
        //            userid2 = Permission.GetCurrentUserId();
        //        }
        //        RadComboBox combo = item.FindControl("cbCitis") as RadComboBox;
        //        if (cbbCategory.SelectedValue == "")
        //        {
        //            GroupCitiesEds.Where = "it.[CountryID] = 1";
        //        }
        //        else
        //        {
        //            GroupCitiesEds.Where = "it.[CountryID] = " + cbbCategory.SelectedValue;
        //        }
        //        //country = "1";
        //        //String city = userid2.IdtoCity().IdtoName2().ToString();//Permission.GetCurrentUserId().IdtoCity().IdtoName2().ToString();
        //        combo.DataBind();
        //        //combo.Items.Insert(0, new RadComboBoxItem("Choose city"));
        //        //combo.SelectedIndex = 0;
        //        String temp = userid2.IdtoCity().ToString();
        //        for (int i = 0; i <= combo.Items.Count - 1; i++)
        //        {
        //            //String xxx = combo.Items[i].Value;
        //            if (combo.Items[i].Value == temp)
        //            {
        //                combo.Items[i].Selected = true;
        //                //a = combo.SelectedValue;
        //                //return;
        //                break;
        //            }
        //        }
        //        a = combo.SelectedValue;
        //        //if (userid2.IdtoCity() == -1)
        //        //{
        //        //    //a = userid2.IdtoCity().ToString();
        //        //}
        //        //else
        //        //{
        //        //    a = combo.SelectedValue;
        //        //}

        //    }
        }
        protected void RadComboBox2_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            //RadComboBox rdcombo = (RadComboBox)temp.FindControl("RadComboBox3");
            country = e.Value;
            RadComboBox cbbCities = item.FindControl("cbCitis") as RadComboBox;
            GroupCitiesEds.Where = "it.[CountryID] = " + e.Value;
            cbbCities.Items.Clear();
            //cbbCitiescount = 0;
            count = 0;
            cbbCities.DataBind();
        }
        protected void rcbCity_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
        {
            count++;
            if (count == 1)
            {
                a = e.Item.Value;
            }
        }
        protected void rcbCity_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            a = e.Value;

        }
        protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
        {
            if (GroupUserSettingEds.UpdateParameters.Count > 0)
            {
                GroupUserSettingEds.UpdateParameters.Clear();
            }
            GroupUserSettingEds.UpdateParameters.Add("CityID", DbType.Int64, a);
            GroupUserSettingEds.UpdateParameters.Add("CountryID", DbType.Int64, country);
            country = "";

            a = "";
            count = 0;
        }
        protected void RadGrid2_InserCommad(object source, GridCommandEventArgs e)
        {
            if (GroupUserSettingEds.InsertParameters.Count > 0)
            {
                GroupUserSettingEds.InsertParameters.Clear();
            }
            GroupUserSettingEds.InsertParameters.Add("CityID", DbType.Int64, a);
            GroupUserSettingEds.InsertParameters.Add("CountryID", DbType.Int64, country);
            country = "";

            a = "";
            count = 0;
        }

    }

}